<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="物业名称" prop="pmid">
        <el-select v-model="queryParams.pmid" placeholder="请输入物业名称" clearable>
          <el-option
            v-for="item in carsManagement"
            :key="item.pmid"
            :label="item.propertyName"
            :value="item.pmid"
            @keyup.enter.native="handleQuery">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="手机号">
        <el-input
          v-model="queryParams.carsTel"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="充值时间">
        <el-date-picker
          v-model="daterangeCreateTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="支付状态">
        <el-select v-model="queryParams.orderStatus" placeholder="请选择" clearable>
          <el-option label="未支付" :value="0" @keyup.enter.native="handleQuery"></el-option>
          <el-option label="已支付" :value="1" @keyup.enter.native="handleQuery"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['pxy-report:combo:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="comboList">
      <el-table-column label="序号" align="center" prop="comid"/>
      <el-table-column label="物业名称" align="center" prop="propertyManagement.propertyName"/>
      <el-table-column label="车场名称" align="center" prop="carsHome.chname"/>
      <el-table-column label="车牌号" align="center" prop="carsMsg.licenseNumber"/>
      <el-table-column label="手机号" align="center" prop="carsMsg.carsTel"/>
      <el-table-column label="交易金额" align="center" prop="payOrder.orderPrice"/>
      <el-table-column label="支付类型" align="center" prop="payType.typeName"/>
      <el-table-column label="费用类型" align="center" prop="tradingType.typeName"/>
      <el-table-column label="支付状态" align="center" prop="payOrder.orderStatus" :formatter="orderStatus"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleList(scope.row)"
            v-hasPermi="['pxy-report:park:query']"
          >查看
          </el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['pxy-report:combo:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleDelete(scope.row)"
            v-hasPermi="['pxy-report:combo:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {listCombo, getCombo, delCombo, addCombo, updateCombo} from "@/api/pxy-report/combo";
import {getPark} from "@/api/pxy-report/park";
import {listManagement} from "@/api/pxy-cars/management";

export default {
  name: "Combo",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 卡套餐报表格数据
      comboList: [],
      carsManagement: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 费用类型时间范围
      daterangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        createTime: null,
        pmid: null,
        chid: null,
        cmid: null,
        poid: null,
        ptid: null,
        feiid: null,
        carsTel: null,
        orderStatus: null
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
    this.getManagement();
  },
  methods: {
    /** 查询卡套餐报列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      listCombo(this.queryParams).then(response => {
        this.comboList = response.rows;
        console.log(response)
        this.total = response.total;
        this.loading = false;
      });
    },
    getManagement() {
      this.loading = true;
      listManagement(this.queryParams).then(response => {
        this.carsManagement = response.rows;
        console.log(response.rows)
        this.loading = false;
      });
    },
    handleList(row) {
      this.reset();
      const comid = row.comid || this.ids
      getCombo(comid).then(response => {
        this.form = response.data;
        console.log(this.form)
        this.$router.push({
          name: 'combocheck',
          query: {form: this.form, isEditing: true}
        })
      })
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const comid = row.comid || this.ids
      getCombo(comid).then(response => {
        this.form = response.data;
        this.$router.push({
          name: 'combocheck',
          query: {form: this.form, isEditing: false}
        })
      });
    },
    orderStatus(row, col) {
      return row.payOrder.orderStatus === 0 ? '未支付' : '已支付'
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        comid: null,
        code: null,
        status: null,
        deleted: null,
        createTime: null,
        updateTime: null,
        pmid: null,
        chid: null,
        cmid: null,
        poid: null,
        ptid: null,
        feiid: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreateTime = [];
      this.queryParams={}
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const comids = row.comid || this.ids;
      this.$modal.confirm('是否确认删除卡套餐报编号为"' + comids + '"的数据项？').then(function () {
        return delCombo(comids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('pxy-report/combo/export', {
        ...this.queryParams
      }, `combo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
